<?php
	include("../include/config.php");
	include("../include/functions.php");
	
	if($_GET['table']){
		deleterow($_GET['table'],array('page_id'=>$_GET['page_id']));
	
		header("location:../index.php?data=pages&msg=delete");
	}
	if(isset($_POST['page_id']) && $_POST['page_id']==''){
			$pr_id=array_shift($_POST);					$_POST['page_url']=strtolower(htmlspecialchars(str_replace(" ","-",str_replace("'","",$_POST['page_title']))));			
			$_POST['page_title']=htmlspecialchars(str_replace("'","",$_POST['page_title']));
			$url_exists=get_table_data('pages',array('page_url'=>$_POST['page_url']));
			if(count($url_exists)>0){
				$_POST['page_url']=rand().strtolower(htmlspecialchars(str_replace(" ","-",str_replace("'","",$_POST['page_title']))));
			}
			$_POST['created_date']=date("Y-m-d H:i:s");
			
			$_POST['updated_date']=date("Y-m-d H:i:s");
	
			$_POST['page_description']=htmlspecialchars(str_replace("'","",$_POST['page_description']));
			
		//	echo "<pre>";print_r($_POST);
			db_insert('pages',$_POST);
			
			header('location:../index.php?data=pages&msg=success');
			
	}else{
		$product_id=array_shift($_POST);
		
			$_POST['page_url']=strtolower(htmlspecialchars(str_replace(" ","-",str_replace("'","",$_POST['page_title']))));
			$_POST['page_title']=str_replace("'","",$_POST['page_title']);
			$_POST['page_description']=htmlspecialchars(str_replace("'","",$_POST['page_description']));
			
			db_update('pages',$_POST,array('page_id'=>$product_id));
			
			header('location:../index.php?data=pages&msg=updated');
	}
	
?>